/*
 * D3D_Window.h
 *
 * Copyright (c) 2009-2011 [BRN] aka. SWW13.
 *
 * This file is part of [BRN]Lib.
 *
 * [BRN]Lib is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * [BRN]Lib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with [BRN]Lib.  If not, see <http ://www.gnu.org/licenses/>.
 */

#if !defined BRNlib_NoD3D

#pragma once
#include "..\D3D Version.h"
#include "..\..\Core\Mouse.h"
#include "..\Core\Color.h"
#include "..\Core\Draw.h"
#include "..\Core\FontManager.h"
#include "..\..\Tools\Misc.h"
#include <vector>

namespace BRNlib
{
	namespace D3D
	{
		namespace GUI
		{
			class Window
			{			
			public:
					struct Item
					{
						D3DXDevice *pDevice;
						BRNlib::D3D::Core::FontManager *pFont;

						D3DCOLOR c_Text, c_TextBorder;
						
						char *Text;
						POINT *ParentPos;
						POINT Pos;
						POINT Size;

						Item(D3DXDevice *pD3Ddev, D3D::Core::FontManager *pFont, char *Text, POINT *ParentPos, int PosX, int PosY, int SizeX, int SizeY);
						
						void SetColor(D3DCOLOR c_Text, D3DCOLOR c_TextBorder);
						POINT GetAbsPos();
						RECT GetRect();
						
						virtual void Draw(bool MouseOver, bool TextBorder) = 0;
						virtual void Click() = 0;
					};
					struct Label : public Item
					{
						D3DCOLOR c_Border, c_BG_Normal, c_BG_Selected;

						Label(D3DXDevice *pD3Ddev, D3D::Core::FontManager *pFont, char *Text, POINT *ParentPos, int PosX, int PosY, int SizeX, int SizeY);
						
						void SetColor(D3DCOLOR c_Text, D3DCOLOR c_TextBorder);
						
						void Draw(bool MouseOver, bool TextBorder = false);
						void Click();
					};
					struct Button : public Item
					{
						int Alpha;
						void (*OnClick)(Button*);

						D3DCOLOR c_Border, c_BG_Normal, c_BG_Selected;

						Button(D3DXDevice *pD3Ddev, D3D::Core::FontManager *pFont, char *Text, POINT *ParentPos, void (*OnClick)(Button*), int PosX, int PosY, int SizeX, int SizeY, int Alpha = 25);
						
						void SetColor(D3DCOLOR c_Text, D3DCOLOR c_TextBorder, D3DCOLOR c_Border, D3DCOLOR c_BG_Normal, D3DCOLOR c_BG_Selected);
						
						void Draw(bool MouseOver, bool TextBorder = false);
						void Click();
					};
					struct CheckBox : public Item
					{
						bool Checked;

						D3DCOLOR c_Border, c_Selected, c_CheckBox, c_BackGround;

						CheckBox(D3DXDevice *pD3Ddev, D3D::Core::FontManager *pFont, char *Text, POINT *ParentPos, int PosX, int PosY, int SizeX, int SizeY);

						void SetColor(D3DCOLOR c_Text, D3DCOLOR c_TextBorder, D3DCOLOR c_Border, D3DCOLOR c_Selected, D3DCOLOR c_CheckBox, D3DCOLOR c_BackGround);
						
						void Draw(bool MouseOver, bool TextBorder = false);
						void Click();
					};

			protected:
					D3DXDevice *pDevice;
					BRNlib::D3D::Core::FontManager *pFont;
					BRNlib::Core::Mouse *pMouse;
					
					RECT Space;
					D3DCOLOR c_Text, c_TextBorder, c_Border, c_BackGround;

					char *Title;
					std::vector<Item*> ItemList;

					POINT Pos;
					POINT InnerPos;
					POINT Size;


				public:
					Window(D3DXDevice *pD3Ddev, BRNlib::D3D::Core::FontManager *pFont, char *Title, int PosX, int PosY, int SizeX, int SizeY);

					void SetSpace(int Left, int Top, int Right, int Bottom);
					void SetColor(D3DCOLOR c_Text, D3DCOLOR c_TextBorder, D3DCOLOR c_Border, D3DCOLOR c_BackGround);
					RECT GetRect();
					RECT GetTitleBar();
					RECT GetTitleBarRect();

					void AddItem(Item* newItem);
					void AddItem(Button* newButton);
					void AddItem(CheckBox* newCheckBox);

					Label *CreateLabel(char *Text, int PosX, int PosY, int SizeX, int SizeY);
					Button *CreateButton(char *Text, void (*OnClick)(Button*), int PosX, int PosY, int SizeX, int SizeY, int Alpha = 25);
					CheckBox *CreateCheckBox(char *Text, int PosX, int PosY, int SizeX, int SizeY);
					
					Item *GetItem(char *Text, int Num = 1);
					Button *GetButton(char *Text, int Num = 1);
					CheckBox *GetCheckBox(char *Text, int Num = 1);
					
					void PanicFunc();

					void Draw(int Alpha = 0, bool TextBorder = true);

				protected:
					void Mouse();
					bool isMoving;
					POINT Move;
					
					void SetInnerPos();
					//bool IsVisible(int ItemIndex);
			};
		}
	}
}

#endif